﻿using System;
using System.Windows.Forms;
using PMIS.UI.Department;
using PMIS.UI.Post;
using PMIS.UI.User;
using WeifenLuo.WinFormsUI.Docking;

namespace PMIS.UI
{
    /// <summary>
    /// 主界面
    /// </summary>
	public partial class MainForm : BaseForm
	{
		#region 单例
		/// <summary>
		/// 本类的实例
		/// </summary>
		private static MainForm _form = null;
		/// <summary>
		/// 用于本类实现单例的Locker
		/// </summary>
		private static object locker = new object();
		/// <summary>
		/// 构造函数
		/// </summary>
		private MainForm()
		{
			InitializeComponent();
		}
		/// <summary>
		/// 获取本窗体的实例
		/// </summary>
		/// <returns></returns>
		public static MainForm GetInstance()
		{
			if (_form == null || _form.IsDisposed)
			{
				lock (locker)
				{
					if (_form == null || _form.IsDisposed)
						_form = new MainForm();
				}
			}

			return _form;
		}
		#endregion

		#region 窗体事件
		/// <summary>
		/// 窗体载入事件
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void MainForm_Load(object sender, EventArgs e)
		{
			//	欢迎页
			WelcomeForm.GetInstance().Show(mainDockPanel, DockState.Document);
		}
		/// <summary>
		/// 窗体关闭事件
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
		{
			if (ShowYesNoMessage("你确定要退出系统吗？") == DialogResult.Yes)
			{
				this.Dispose();
				Application.Exit();
			}
			else
			{
				e.Cancel = true;
			}
		}
		#endregion

		#region 菜单事件

		private void 退出XToolStripMenuItem_Click(object sender, EventArgs e)
		{
			if (ShowYesNoMessage("你确定要退出系统吗？") == DialogResult.Yes)
			{
				this.Dispose();
				Application.Exit();
			}
		}

		private void 人员管理ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			try
			{
				人员列表 form = 人员列表.GetInstance();
				if (form == null)
					throw new Exception("获取人员管理窗体时发生错误!");

				form.Show(mainDockPanel, DockState.Document);
				form.Activate();
			}
			catch (Exception ex)
			{
				ShowExceptionMessage(ex);
			}
		}

		private void 岗位管理ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			try
			{
				岗位列表 form = 岗位列表.GetInstance();
				if (form == null)
					throw new Exception("获取岗位信息维护窗体时发生错误!");

				form.Show(mainDockPanel, DockState.Document);
				form.Activate();
			}
			catch (Exception ex)
			{
				ShowExceptionMessage(ex);
			}
		}

		private void 岗位等级管理ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			try
			{
				岗位等级信息管理 form = 岗位等级信息管理.GetInstance();
				if (form == null)
					throw new Exception("获取岗位等级信息维护窗体时发生错误!");

				form.ShowDialog();
			}
			catch (Exception ex)
			{
				ShowExceptionMessage(ex);
			}
		}

		private void 部门班组管理ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			try
			{
				部门班组信息维护 form = 部门班组信息维护.GetInstance();
				if (form == null)
					throw new Exception("获取岗位信息维护窗体时发生错误!");

				form.Show(mainDockPanel, DockState.Document);
				form.Activate();
			}
			catch (Exception ex)
			{
				ShowExceptionMessage(ex);
			}
		}
		#endregion

		
	}
}
